<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>被测人管理</title>
<!-- 导入jquery核心类库 -->
<%@include file="../include/jqueryeasyui.jsp"%>

<script type="text/javascript">

$(function(){
	
	main();
	
});

	function main(){
		
		initDatagrid();
		initBtn();
		initsizerulerwindow();
		initSaveBtn();
	}
	
	
	
	function initDatagrid(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/sizeRuler/page.list.ashx",
			idField : 'id',
			columns : columns,
			pageList: [10,50,100,200],
			pagination:true,
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>"
			
		});
	}
	
	function initBtn(){
		
		$('#search').click(doSearch);
		$('#add').click(doAdd);
		$('#edit').click(doEdit);
		
	}
	
	function doAdd(){
		
		$('#sizerulerwindow').form('clear');
		$('#sizerulerwindow *').trigger('blur');// 离焦
		$('#sizerulerwindow').window("open").window('setTitle', '套号规则');
		$('#sizeRuleID').val("-1");
	}
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
	        $("input[name='sizeRuleID']").val(rowData.sizeRuleID);
	        $("input[name='sRName']").val(rowData.sRName);
			

			// 弹出窗口
			  
			$("#sizerulerwindow").window('open').window('setTitle', '修改规则名称');
        } 
	}
	
	
	function initsizerulerwindow(){
		//初始化销售员窗口
		$('#sizerulerwindow').window({
	           title: '名单详情',
	           width: 500,
	           modal: true,
	           shadow: true,
	           closed: true,
	           height: 200,
	           resizable:true,
	           left:550,
	           top:300,
	           
	           
	       });
	

	}

	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#search_content').val();
	     queryParams.sRName = searchcontent;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){		
		reloadgrid();
	}
	
	 
	
	 

	


	// 定义列
	var columns = [ [  {
		field : 'sRName',
		title : '规则名称',
		width : 200,	
	}, {
		field : 'sizeRuleID',
		title : '操作',
		width : 200,
		
		formatter:formatterId
	} ] ];
	
	
	 
	
	function formatterId(value,row,index) {
		return "<a onclick=addHK("+index+") href=#>添加号库</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
		"<a onclick=addXK("+index+") href=#>添加型库</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
 		"<a onclick=addCS("+index+") href=#>添加参数</a>";
	}
	
	function addHK(index){
		  $('#grid').datagrid('selectRow',index);// 关键在这里  
		    var row = $('#grid').datagrid('getSelected'); 
	    	var parent$ = self.parent.$;      //找到父级DOM  
	 		var sRName = row.sRName
	    	var text =sRName+"号库";
	        var url="page.hodo.srheight.ashx?sizeRuleID="+row.sizeRuleID;
			if (parent$("#tabs").tabs('exists', text)) {
				parent$('#tabs').tabs('select', text);
			} else {
				var content = '<div style="width:100%;height:100%;overflow:hidden;">'
						+ '<iframe src="'
						+ url
						+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

					parent$('#tabs').tabs('add', {
					title : text,
					content : content,
					closable : true
				});
			}
	    }
	
	function addXK(index){
		  $('#grid').datagrid('selectRow',index);// 关键在这里  
		    var row = $('#grid').datagrid('getSelected'); 
	    	var parent$ = self.parent.$;      //找到父级DOM  
	 		var sRName = row.sRName
	    	var text =sRName+"型库";
	        var url="page.hodo.srgirth.ashx?sizeRuleID="+row.sizeRuleID;
			if (parent$("#tabs").tabs('exists', text)) {
				parent$('#tabs').tabs('select', text);
			} else {
				var content = '<div style="width:100%;height:100%;overflow:hidden;">'
						+ '<iframe src="'
						+ url
						+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

					parent$('#tabs').tabs('add', {
					title : text,
					content : content,
					closable : true
				});
			}
	    }
	function addHXK(index){
		  $('#grid').datagrid('selectRow',index);// 关键在这里  
		    var row = $('#grid').datagrid('getSelected'); 
	    	var parent$ = self.parent.$;      //找到父级DOM  
	 		var sRName = row.sRName
	    	var text =sRName+"号型库";
	        var url="page.sizerule_hxk.ashx?sizeRuleID="+row.sizeRuleID;
			if (parent$("#tabs").tabs('exists', text)) {
				parent$('#tabs').tabs('select', text);
			} else {
				var content = '<div style="width:100%;height:100%;overflow:hidden;">'
						+ '<iframe src="'
						+ url
						+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

					parent$('#tabs').tabs('add', {
					title : text,
					content : content,
					closable : true
				});
			}
	    }
	function addCS(index){
		  $('#grid').datagrid('selectRow',index);// 关键在这里  
		    var row = $('#grid').datagrid('getSelected'); 
	    	var parent$ = self.parent.$;      //找到父级DOM  
	 		var sRName = row.sRName
	    	var text =sRName+"参数";
	        var url="page.sizerule_cs.ashx?sizeRuleID="+row.sizeRuleID;
			if (parent$("#tabs").tabs('exists', text)) {
				parent$('#tabs').tabs('select', text);
			} else {
				var content = '<div style="width:100%;height:100%;overflow:hidden;">'
						+ '<iframe src="'
						+ url
						+ '" scrolling="auto" style="width:100%;height:100%;border:0;" ></iframe></div>';

					parent$('#tabs').tabs('add', {
					title : text,
					content : content,
					closable : true
				});
			}
	    }

	
	function formatterDate(value){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(value);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	
	function doFuQuan(index){
	    $('#grid').datagrid('selectRow',index);// 关键在这里  
	    var row = $('#grid').datagrid('getSelected'); 

	    if(row){
			$.messager.alert("提示", "正在完善...", 'info');
		}
	}
	
	function formatterSex(value,row,index){
		if(row.sex==1){
			return "男";
		}else if(row.sex==2){
			return "女";
		}
	}


		
		

	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});

	function initSaveBtn(){
		
	
		$('#save').click(function(){
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/sizeRuler/page.saveOrUpdate.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#sizerulerwindow').window('close');
							// 清除表单数据
							$('#sizerulerwindow').form('clear');
							$('#sizerulerwindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data == "conflict"){
							$.messager.alert('消息','规则名称重复','info');
						}
						else{
							data =new String(data);
							if(data.charAt(0)=='<'){
								$.messager.alert('消息','没有权限 ','info');
							}else{
								$.messager.alert('消息','操作失败 ','info');
							}
							
						}
							
					});
				}
				
			});	
	
	}

	
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center"><table id="grid"></table></div>

		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
		<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >编辑</a>
		
		
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;规则名称: <input id="search_content" name="search_content" class="easyui-textbox" style="width:200px">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
		</div>
	</div>
	
	
	<div  class="easyui-window" title="品类详情" id="sizerulerwindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px;">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			</div>
		</div>
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform">
				<table class="table-edit" width="80%" align="center">
					
					<tr class="title">
						<td colspan="2">套号规则详情</td>
					</tr>
					
					
	            	   	<tr>
						<td >规则名称</td>
						<td><input id="sRName" name="sRName" type="text" class="easyui-validatebox"  required="true"  /></td>
						<input type="hidden" id="sizeRuleID" name="sizeRuleID">
					</tr>
					
					 
					
					</table>
			</form>
		</div>
	</div>
</body>
</html>